<style scoped>
.tab_img{font-size: 26px;}
</style>
<template>
  <div class="tabs_menu" v-show="is_show && index!==-1">
    <van-tabbar :model-value="index" :fixed="false">
      <van-tabbar-item v-for="row in list" :badge="row.badge" @click="click(row)">
        <template #icon="props">
          <IconImg class="tab_img" :value="row.icon || row.head_img" :disable="!props.active"></IconImg>
        </template>
        <span class="text-ellipsis">{{row.title}}</span>
      </van-tabbar-item>
    </van-tabbar>
  </div>
</template>

<script>

import {page_card} from "@/js/api_tool.js";
import router, {href_path, href_handle} from "@/vue_plugin/router_auto.js";
import {eq} from "@/js/s94_tool.js";
import IconImg from "@/components/widget/IconImg.vue";

export default {
  components: {IconImg},
  data(){
    return {
      is_show: true,
      list: [],
    }
  },
  computed: {
    index(){
      let now_path = router.currentRoute.value.path;
      let now_param = router.currentRoute.value.query;
      let res = this.list.findIndex(row=>{
        if (!row._path_data_list){
          let path_param = href_path(row.href).split('?');
          let path = path_param.shift();
          let param = {};
          (path_param.shift()||'').split('&').forEach(v=>{
            if (!v) return;
            let kv = v.split('=');
            param[kv[0]] = kv[1]||'';
          })
          row._path_data_list = [{path, param}];
          if (path === '/'){
            row._path_data_list.push({path:'/index', param});
          }
          if (path === '/index'){
            row._path_data_list.push({path:'/', param});
          }
        }

        return row._path_data_list.some(path_data=>{
          return eq(now_path, path_data.path) && eq(now_param, path_data.param, 'undefined*');
        })
      })
      return res;
    },
  },
  methods: {
    click(row){
      href_handle(row.href);
    },
  },
  mounted(){
    // 请求底部的列表
    page_card('footer_menu').then(card_list=>{
      if (card_list.length) {
        this.list = card_list[0].list;
      }
    })
  }
}
</script>